package brave.chat.bot.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: weiyi
 * @Description:
 * @Date 2025/2/28 21:24
 * @ClassName AiController
 * @Version 1.0
 */

@RestController
@RequestMapping("/ai")
public class AIController {


    //智能对话的客户端
    private final ChatClient chatClient;

    public AIController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    @GetMapping("/ai01")
    public String generation(
            @RequestParam(value = "message",
                    defaultValue = "给我讲个笑话")
            String message) {

        return this.chatClient.prompt()  // prompt:提示词
                .user(message) // message:用户输入的信息
                .call() // 调用大模型 远程请求大模型
                .content(); // 获取大模型的返回结果
    }
}

